package com.lyq.mr.homework.planThree;

import org.apache.hadoop.io.*;

import java.io.IOException;

public class NumSortingCompactor implements RawComparator<LongWritable> {

    private LongWritable key1=new LongWritable();
    private LongWritable key2=new LongWritable();

    private DataInputBuffer buffer=new DataInputBuffer();


    @Override
    public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
        try {
            buffer.reset(b1, s1, l1);                   // parse key1
            key1.readFields(buffer);

            buffer.reset(b2, s2, l2);                   // parse key2
            key2.readFields(buffer);

            buffer.reset(null, 0, 0);                   // clean up reference
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        return compare(key1, key2);
    }

    @Override
    public int compare(LongWritable o1, LongWritable o2) {
         return -o1.compareTo(o2);
    }
}
